package com.douqu.game.core.factory;

import java.text.MessageFormat;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-03-24 17:19
 */
public class DatabaseConfig {

    private String host;

    private String port;

    private String db;

    private String user;

    private String pwd;

    private String url;

    public DatabaseConfig(String host, String port, String db, String user, String pwd)
    {
        this.host = host;
        this.port = port;
        this.db = db;
        this.user = user;
        this.pwd = pwd;

        String str = "jdbc:mysql://{0}:{1}/{2}?useUnicode=true&characterEncoding=utf-8&autoReconnect=true";
        this.url = MessageFormat.format(str, host, port, db);
    }

    public DatabaseConfig(String host, String port, String user, String pwd)
    {
        this.host = host;
        this.port = port;
        this.user = user;
        this.pwd = pwd;

        String str = "jdbc:mysql://{0}:{1}/";
        this.url = MessageFormat.format(str, host, port);
    }

    public void initUrl(String dbname)
    {
        String str = "jdbc:mysql://{0}:{1}/{2}";
        this.url = MessageFormat.format(str, host, port, dbname);
    }

    public String getUrl() {
        return url;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getDb() {
        return db;
    }

    public void setDb(String db) {
        this.db = db;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DatabaseConfig that = (DatabaseConfig) o;

        if (db != null ? !db.equals(that.db) : that.db != null) return false;
        if (host != null ? !host.equals(that.host) : that.host != null) return false;
        if (port != null ? !port.equals(that.port) : that.port != null) return false;
        return true;
    }

}
